"""
fastapi 服务
"""
import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware

def create_app():
    app = FastAPI(title="小说合理性分析", version='1.0')
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    mount_routes(app)
    return app


def mount_routes(app: FastAPI):
    from service.api import novel_analyze_api

    app.post(
        path='/novelAnalyze', summary="小说分析"
    )(novel_analyze_api)


my_app = create_app()
my_app.mount("/uploadFiles", StaticFiles(directory="uploadFiles"), name="uploadFiles")


if __name__ == '__main__':
    uvicorn.run(app=my_app, host="0.0.0.0", port=9009, reload=False)
